package com.consumer.controller;


import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.consumer.asyncTask.ExecuteTask;
import com.consumer.config.URLConfig;
import com.consumer.entity.TProduct;
import com.consumer.entity.TProject;
import com.consumer.service.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;

/**
 * 项目EPIC任务(TEpic)表控制层
 *
 * @author makejava
 * @since 2024-04-28 14:35:06
 */
@RestController
@RequestMapping("consumer")
public class ConsumerController {

    //    private static final ExecutorService executor = Executors.newFixedThreadPool(10);

    @Resource
    DevopsBucketService devopsBucketService;
    @Resource
    DevopsBucketFileService devopsBucketFileService;


    @Resource
    ExecuteTask executeTask;
    // 202004100000061
    //1633350981910249472
    @PostMapping("tt")
    public void tt() {
        HashMap<String, Object> paramMap2 = new HashMap<>();
        String projects = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProject", paramMap2);
        List<TProject> projectList = JSON.parseArray(projects, TProject.class);
        BlockingQueue<String> queue = projectList.stream().filter(Objects::nonNull).map(TProject::getProjectId).collect(Collectors.toCollection(LinkedBlockingQueue::new));
        System.out.println("项目迁移共计" + queue.size() + "个项目");

        executeTask.startTasks(queue);
    }

    @PostMapping("tt2")
    public void tt2() {
        HashMap<String, Object> paramMap = new HashMap<>();
        String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProduct", paramMap);
        List<TProduct> planeList = JSON.parseArray(plans, TProduct.class);
        BlockingQueue<String> queue = planeList.stream().map(TProduct::getProductId).collect(Collectors.toCollection(LinkedBlockingQueue::new));

//        queue.clear();
        try {
//            queue.put("202207290000006");
            executeTask.startProductTasks(queue);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    @PostMapping("/test")
//    public void threadTest() {
//
//        HashMap<String, Object> paramMap2 = new HashMap<>();
//        String projects = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProject", paramMap2);
//        List<TProject> projectList = JSON.parseArray(projects, TProject.class);
//        for (TProject project : projectList) {
//            try {
//                threadPoolService.threadTest(project.getProjectId());
//            } catch (Exception e) {
//                System.out.println("小意外");
//            }
//        }
//    }

//    @PostMapping("/test2")
//    public void threadTest2() {
//        HashMap<String, Object> paramMap = new HashMap<>();
//        String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProductPlan", paramMap);
//        List<TProductPlane> planeList = JSON.parseArray(plans, TProductPlane.class);
//        for (TProductPlane tProductPlane : planeList) {
//            try {
//                threadPoolService.threadTest2(tProductPlane.getSystemId());
//            } catch (Exception e) {
//                System.out.println("小意外");
//            }
//        }
//    }


//    @PostMapping("/testProject")
//    public void testProject() {
//
//        HashMap<String, Object> paramMap2 = new HashMap<>();
//        String projects = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProject", paramMap2);
//        List<TProject> projectList = JSON.parseArray(projects, TProject.class);
//
//        BlockingQueue<String> queue = projectList.stream().map(TProject::getProjectId).collect(Collectors.toCollection(LinkedBlockingQueue::new));
//        int numThreads = 10;
//        for (int i = 0; i < numThreads; i++) {
//            TestThreadProject thread = new TestThreadProject(queue);
//            thread.start();
//        }
//    }
//
//
//    @PostMapping("/testProduct")
//    public void testProduct() {
//        HashMap<String, Object> paramMap = new HashMap<>();
//        String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProductPlan", paramMap);
//        List<TProductPlane> planeList = JSON.parseArray(plans, TProductPlane.class);
//        BlockingQueue<String> queue = planeList.stream().map(TProductPlane::getSystemId).distinct().collect(Collectors.toCollection(LinkedBlockingQueue::new));
//        int numThreads = 10;
//        for (int i = 0; i < numThreads; i++) {
//            TestThreadProduct thread = new TestThreadProduct(queue);
//            thread.start();
//        }
//    }
//

//    @PostMapping("migrate")
//    public void migrate() {
//        try {
//            HashMap<String, Object> paramMap = new HashMap<>();
//            String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProductPlan", paramMap);
//            List<TProductPlane> planeList = JSON.parseArray(plans, TProductPlane.class);
//
//            int count = 1;
//
//            for (TProductPlane tProductPlane : planeList) {
//                try {
//                    migrateProductDemand(tProductPlane.getSystemId());
//                    migrateProductBucket(tProductPlane.getSystemId());
//                    System.out.println("产品" + tProductPlane.getProductPlaneName() + "正在迁移");
//                } catch (Exception e) {
//                    System.out.println("小意外");
//                }
//
//            }
//
//
//            System.out.println(planeList);
//            HashMap<String, Object> paramMap2 = new HashMap<>();
//            String projects = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProject", paramMap2);
//            List<TProject> projectList = JSON.parseArray(projects, TProject.class);
//            System.out.println(projectList);
//            int count2 = 1;
//            for (TProject tProject : projectList) {
//                try {
//                    System.out.println("产品" + tProject.getProjectName() + "正在迁移");
//                    System.out.println("项目第" + count2++ + "正在迁移");
//                    migrateDemand(tProject.getProjectId());
//                } catch (Exception e) {
//                    System.out.println("项目小意外");
//                }
//            }
//
//            for (int i = 0; i < 100; i++) {
//                System.out.println("终于跑完了啊啊啊啊啊啊啊啊啊");
//            }
//        } catch (Exception e) {
//            System.out.println(e.getMessage());
//        }
//
//    }
//
//
//    //迁移项目以及交付物
//    @PostMapping("migrateDemand")
//    public void migrateDemand(String projectId) {
//        //查询所有计划
//        HashMap<String, Object> paramMap4 = new HashMap<>();
//        String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProjectPlan", paramMap4);
//        List<TPlane> planeList = JSON.parseArray(plans, TPlane.class);
//        Map<String, String> planMap = planeList.stream().collect(Collectors.toMap(TPlane::getSystemId, TPlane::getPlaneId));
//
//        HashMap<String, Object> paramMap6 = new HashMap<>();
//
//
//        //查询所有用户
//        String users = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllUser", paramMap6);
//        List<VUserData> userDataList = JSON.parseArray(users, VUserData.class);
//
//        //12345 -李XX
//        Map<String, String> userKV = userDataList.stream().collect(Collectors.toMap(VUserData::getAccountId, VUserData::getName));
//        //12345-lixx
//        Map<String, String> userKV2 = userDataList.stream().collect(Collectors.toMap(VUserData::getAccountId, VUserData::getAccountName));
//        //查询出所有的 epic
//        HashMap<String, Object> paramMap = new HashMap<>();
//        paramMap.put("systemId", projectId);
//        String epics = HttpUtil.post(URLConfig.CONSUMER_URL + "queryEpicBySystemId", paramMap);
//        List<TEpic> epicList = JSON.parseArray(epics, TEpic.class);
//
//        //查询出所有的 story
//        HashMap<String, Object> paramMap2 = new HashMap<>();
//        paramMap2.put("systemId", projectId);
//        String storys = HttpUtil.post(URLConfig.CONSUMER_URL + "queryStoryBySystemId", paramMap2);
//        List<TStory> storyList = JSON.parseArray(storys, TStory.class);
//
//        //查询出所有的 task 任务
//        HashMap<String, Object> paramMap3 = new HashMap<>();
//        paramMap3.put("systemId", projectId);
//        String tasks = HttpUtil.post(URLConfig.CONSUMER_URL + "queryTaskBySystemId", paramMap3);
//        List<TTask> tTasks = JSON.parseArray(tasks, TTask.class);
//
//        HashMap<String, Object> paramMap5 = new HashMap<>();
//        paramMap5.put("projectId", projectId);
//        String buckets = HttpUtil.post(URLConfig.CONSUMER_URL + "queryBucketByProjectId", paramMap5);
//        List<TBucket> tBucketList = JSON.parseArray(buckets, TBucket.class);
//
//
//        List<DevopsDemand> devopsDemands = new ArrayList<>();
//        List<DevopsTask> devopsTasks = new ArrayList<>();
//        List<DevopsBucket> devopsBuckets = new ArrayList<>();
//
//
//        //保存 bucket
//        if (Optional.ofNullable(tBucketList).isPresent()) {
//            for (TBucket tBucket : tBucketList) {
//                DevopsBucket devopsBucket = DevopsBucket.builder().bucketId(planMap.get(tBucket.getSystemId())).systemType("1").planId(planMap.get(tBucket.getSystemId())).bucketName(tBucket.getBucketName()).createUserName(userKV.get(tBucket.getCreateUser())).createUser(tBucket.getCreateUser()).createTime(tBucket.getCreateTime()).updateTime(tBucket.getUpdateTime()).lesseeId("devops").updateUser(tBucket.getUpdateUser()).updateUserName(userKV.get(tBucket.getUpdateUser())).build();
//                devopsBuckets.add(devopsBucket);
//            }
//            devopsBucketService.saveBatch(devopsBuckets);
//        }
//
//        HashMap<String, Object> paramMap8 = new HashMap<>();
//        paramMap8.put("projectId", projectId);
//        String bucketFiles = HttpUtil.post(URLConfig.CONSUMER_URL + "queryBucketFileByProjectId", paramMap8);
//        List<TBucketFile> bucketFileList = JSON.parseArray(bucketFiles, TBucketFile.class);
//        List<DevopsBucketFile> devopsBucketFiles = new ArrayList<>();
//        if (Optional.ofNullable(bucketFileList).isPresent()) {
//            bucketFileList.forEach(e -> {
//                DevopsBucketFile build = DevopsBucketFile.builder().bucketFileId(e.getBucketFileId()).bucketFilePid(e.getBucketFilePid()).bucketFileCode(e.getBucketFileCode()).bucketFileName(e.getBucketFileName()).bucketFileRemark(e.getBucketFileRemark()).bucketFileType(e.getBucketFileType()).bucketFileUrl(e.getBucketFileUrl())
//                        //转为主计划 ID
//                        .bucketId(planMap.get(e.getBucketId())).globalId(e.getSeq()).isValid("Y").lesseeId("devops").createTime(e.getCreateTime()).createUser(e.getCreateUser()).createUserName(e.getCreateUserName()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).updateUserName(e.getUpdateUserName()).source("5").build();
//                devopsBucketFiles.add(build);
//            });
//            devopsBucketFileService.saveBucketFile(devopsBucketFiles);
//        }
//        if (Optional.ofNullable(epicList).isPresent()) {
//            epicList.forEach(e -> {
//                DevopsDemand build = DevopsDemand.builder().id(e.getEpicId()).demandSource(e.getSource() == null ? "4" : "3").code(StringUtils.isBlank(e.getCode()) ? "D" + System.nanoTime() : e.getCode()).demandType(e.getType()).fullId(e.getEpicId()).isLeaf("0").manager(e.getMoniterUser()).managerAccount(userKV2.get(e.getMoniterUser())).managerName(userKV.get(e.getMoniterUser())).introducer(e.getMoniterUser()).introducerAccount(userKV2.get(e.getMoniterUser())).introducerName(userKV.get(e.getMoniterUser())).parentId("-1").taskGroupId(e.getTaskGroupId()).planDetailId(e.getPlaneDetailId()).planId(e.getPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).commitTime(LocalDateTime.now()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
////                            .num((long)e.getSort())
//                        .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).createUserName(userKV.get(e.getCreateUser())).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).updateUserName(userKV.get(e.getUpdateUser())).lesseeId("devops").build();
//                devopsDemands.add(build);
//            });
//            devopsDemandService.saveDemandList(devopsDemands);
//            devopsDemands.clear();
//        }
//
//        if (Optional.ofNullable(storyList).isPresent()) {
//            storyList.forEach(e -> {
//                DevopsDemand build = DevopsDemand.builder().id(e.getStoryId()).demandSource(e.getSource() == null ? "4" : "3").code(StringUtils.isBlank(e.getCode()) ? "D" + System.nanoTime() : e.getCode()).demandType(e.getType()).fullId(e.getEpicId() + "/" + e.getStoryId()).isLeaf("1").manager(e.getMoniterUser()).managerAccount(userKV2.get(e.getMoniterUser())).managerName(userKV.get(e.getMoniterUser())).introducer(e.getMoniterUser()).introducerAccount(userKV2.get(e.getMoniterUser())).introducerName(userKV.get(e.getMoniterUser())).parentId(e.getEpicId()).taskGroupId(e.getTaskGroupId()).planDetailId(e.getPlaneDetailId()).planId(e.getPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).commitTime(LocalDateTime.now()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
////                            .num((long)e.getSort())
//                        .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).createUserName(userKV.get(e.getCreateUser()) == null ? "devops" : userKV.get(e.getCreateUser())).updateUserName(userKV.get(e.getUpdateUser()) == null ? "devops" : userKV.get(e.getUpdateUser())).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser())
//
//                        .lesseeId("devops").build();
//                devopsDemands.add(build);
//            });
//            devopsDemandService.saveDemandList(devopsDemands);
//            devopsDemands.clear();
//        }
//
//        if (Optional.ofNullable(tTasks).isPresent()) {
//            tTasks.forEach(t -> {
////                DevopsTask build = DevopsTask.builder().id(e.getTaskId()).code(StringUtils.isBlank(e.getCode()) ? "D" + System.nanoTime() : e.getCode()).fullId(e.getEpicId() + "/" + e.getStoryId() + "/" + e.getTaskId()).isLeaf("0").manager(e.getMoniterUser()).managerName(userKV.get(e.getMoniterUser())).version(1L).parentId(e.getStoryId()).taskGroupId(e.getTaskGroupId()).planDetailId(e.getPlaneDetailId()).planId(e.getPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
//////                            .num((long)e.getSort())
////                        .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).createUserName(userKV.get(e.getCreateUser()) == null ? "devops" : userKV.get(e.getCreateUser())).updateUserName(userKV.get(e.getUpdateUser()) == null ? "devops" : userKV.get(e.getUpdateUser())).lesseeId("devops").build();
////                devopsTasks.add(build);
//                DevopsTask devopsTask = new DevopsTask();
////                                DevopsTask taskBuild = DevopsTask.builder()
//                devopsTask.setId(t.getTaskId());
//                devopsTask.setCode(StringUtils.isBlank(t.getCode()) ? "D" + System.nanoTime() : t.getCode());
//                devopsTask.setFullId(t.getEpicId() + "/" + t.getStoryId() + "/" + t.getTaskId());
//                devopsTask.setIsLeaf("0");
//                devopsTask.setManager(t.getMoniterUser());
//                devopsTask.setManagerName(userKV.get(t.getMoniterUser()));
//                devopsTask.setVersion(1L);
//                devopsTask.setParentId(t.getStoryId());
//                devopsTask.setTaskGroupId(t.getTaskGroupId());
//                devopsTask.setPlanDetailId(t.getPlaneDetailId());
//                devopsTask.setPlanId(t.getPlaneId());
//                devopsTask.setProjectId(t.getSystemId());
//                devopsTask.setName(t.getTitle());
//                devopsTask.setSort(t.getSort());
//                devopsTask.setStatus(t.getStatus());
//                devopsTask.setRemark(StringUtils.isBlank(t.getRemark()) ? t.getTitle() : t.getRemark());
//                devopsTask.setPredictBeginTime(t.getPredictBeginTime());
//                devopsTask.setPredictEndTime(t.getPredictEndTime());
//                devopsTask.setPracticalBeginTime(t.getPracticalBeginTime());
//                devopsTask.setPracticalEndTime(t.getPracticalEndTime());
//                devopsTask.setHoursOfWork(t.getHoursOfWork());
//                devopsTask.setHoursOfWorkTruth(t.getHoursOfWorkTruth());
//                devopsTask.setHoursOfWorkUnit(t.getHoursOfWorkUnit());
////                            .num((long)e.getSort())
//                devopsTask.setLevel(t.getLevel());
//                devopsTask.setIsValid("Y");
//                devopsTask.setCreateTime(t.getCreateTime());
//                devopsTask.setCreateUser(t.getCreateUser());
//                devopsTask.setUpdateTime(t.getUpdateTime());
//                devopsTask.setUpdateUser(t.getUpdateUser());
//                devopsTask.setCreateUserName(userKV.get(t.getCreateUser()) == null ? "devops" : userKV.get(t.getCreateUser()));
//                devopsTask.setUpdateUserName(userKV.get(t.getUpdateUser()) == null ? "devops" : userKV.get(t.getUpdateUser()));
//                devopsTask.setLesseeId("devops");
//                devopsTasks.add(devopsTask);
//            });
//            devopsTaskService.saveTaskList(devopsTasks);
//        }
//    }
//
//
//    //迁移产品
//    @PostMapping("migrateProductDemand")
//    public void migrateProductDemand(String productId) {
//        HashMap<String, Object> paramMap4 = new HashMap<>();
//        String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProjectPlan", paramMap4);
//        List<TPlane> planeList = JSON.parseArray(plans, TPlane.class);
//
//        HashMap<String, Object> paramMap6 = new HashMap<>();
//
//        String users = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllUser", paramMap6);
//        List<VUserData> userDataList = JSON.parseArray(users, VUserData.class);
//
//        Map<String, String> userKV = userDataList.stream().collect(Collectors.toMap(VUserData::getAccountId, VUserData::getName));
//        Map<String, String> userKV2 = userDataList.stream().collect(Collectors.toMap(VUserData::getAccountId, VUserData::getAccountName));
//
//        HashMap<String, Object> paramMap = new HashMap<>();
//        paramMap.put("systemId", productId);
//        String epics = HttpUtil.post(URLConfig.CONSUMER_URL + "queryProductEpicBySystemId", paramMap);
//        List<TProductEpic> epicList = JSON.parseArray(epics, TProductEpic.class);
//
//
//        HashMap<String, Object> paramMap2 = new HashMap<>();
//        paramMap2.put("systemId", productId);
//        String storys = HttpUtil.post(URLConfig.CONSUMER_URL + "queryProductStoryBySystemId", paramMap2);
//        List<TProductStory> storyList = JSON.parseArray(storys, TProductStory.class);
//
//
//        HashMap<String, Object> paramMap3 = new HashMap<>();
//        paramMap3.put("systemId", productId);
//        String tasks = HttpUtil.post(URLConfig.CONSUMER_URL + "queryProductTaskBySystemId", paramMap3);
//        List<TProductTask> tTasks = JSON.parseArray(tasks, TProductTask.class);
//
//
//        Set<String> isSet = new HashSet<>();
//        List<DevopsDemand> devopsDemands = new ArrayList<>();
//        List<DevopsTask> devopsTasks = new ArrayList<>();
//        if (Optional.ofNullable(epicList).isPresent()) {
//            epicList.forEach(e -> {
//                String id = "";
//                if (isSet.contains(e.getProductEpicId())) {
//                    id = IdUtil.randomUUID();
//                } else {
//                    id = e.getProductEpicId();
//                }
//                isSet.add(id);
//                DevopsDemand build = DevopsDemand.builder().id(id).demandSource(e.getSource() == null ? "4" : "3").code(StringUtils.isBlank(e.getCode()) ? "D" + System.nanoTime() : e.getCode()).demandType(e.getType()).fullId(id).isLeaf("0").manager(e.getMoniterUser()).managerAccount(userKV2.get(e.getMoniterUser())).managerName(userKV.get(e.getMoniterUser())).introducer(e.getMoniterUser()).introducerAccount(userKV2.get(e.getMoniterUser())).introducerName(userKV.get(e.getMoniterUser())).parentId("-1").taskGroupId(e.getProductTaskGroupId()).planDetailId(e.getProductPlaneDetailId()).planId(e.getProductPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).commitTime(LocalDateTime.now()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
////                            .num((long)e.getSort())
//                        .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).createUserName(userKV.get(e.getCreateUser()) == null ? "devops" : userKV.get(e.getCreateUser())).updateUserName(userKV.get(e.getUpdateUser()) == null ? "devops" : userKV.get(e.getUpdateUser())).lesseeId("devops").build();
//                devopsDemands.add(build);
//            });
//            devopsDemandService.saveDemandList(devopsDemands);
//            devopsDemands.clear();
//        }
//
//        if (Optional.ofNullable(storyList).isPresent()) {
//            storyList.forEach(e -> {
//                String id = "";
//                if (isSet.contains(e.getProductStoryId())) {
//                    id = IdUtil.randomUUID();
//                } else {
//                    id = e.getProductStoryId();
//                }
//                isSet.add(id);
//                DevopsDemand build = DevopsDemand.builder().id(id).demandSource(e.getSource() == null ? "4" : "3").code(StringUtils.isBlank(e.getCode()) ? "D" + System.nanoTime() : e.getCode()).demandType(e.getType()).fullId(e.getProductEpicId() + "/" + id).isLeaf("1").manager(e.getMoniterUser()).managerAccount(userKV2.get(e.getMoniterUser())).managerName(userKV.get(e.getMoniterUser())).introducer(e.getMoniterUser()).introducerAccount(userKV2.get(e.getMoniterUser())).introducerName(userKV.get(e.getMoniterUser())).parentId(e.getProductEpicId()).taskGroupId(e.getProductTaskGroupId()).planDetailId(e.getProductPlaneDetailId()).planId(e.getProductPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).commitTime(LocalDateTime.now()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
////                            .num((long)e.getSort())
//                        .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).createUserName(userKV.get(e.getCreateUser()) == null ? "devops" : userKV.get(e.getCreateUser())).updateUserName(userKV.get(e.getUpdateUser()) == null ? "devops" : userKV.get(e.getUpdateUser())).lesseeId("devops").build();
//                devopsDemands.add(build);
//            });
//            devopsDemandService.saveDemandList(devopsDemands);
//            devopsDemands.clear();
//        }
//
//        if (Optional.ofNullable(tTasks).isPresent()) {
//            tTasks.forEach(t -> {
////                String id = "";
////                if (isSet.contains(e.getProductTaskId())) {
////                    id = IdUtil.randomUUID();
////                } else {
////                    id = e.getProductTaskId();
////                }
////                isSet.add(id);
////                DevopsTask build = DevopsTask.builder().id(id).code(StringUtils.isBlank(e.getCode()) ? "D" + System.nanoTime() : e.getCode()).fullId(e.getProductEpicId() + "/" + e.getProductStoryId() + "/" + id).isLeaf("0").manager(e.getMoniterUser()).managerName(userKV.get(e.getMoniterUser())).version(1L).parentId(e.getProductStoryId()).taskGroupId(e.getProductTaskGroupId()).planDetailId(e.getProductPlaneDetailId()).planId(e.getProductPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
//////                            .num((long)e.getSort())
////                        .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).createUserName(userKV.get(e.getCreateUser()) == null ? "devops" : userKV.get(e.getCreateUser())).updateUserName(userKV.get(e.getUpdateUser()) == null ? "devops" : userKV.get(e.getUpdateUser())).lesseeId("devops").build();
////                devopsTasks.add(build);
//                DevopsTask devopsTask = new DevopsTask();
////                                DevopsTask taskBuild = DevopsTask.builder()
//                devopsTask.setId(t.getProductTaskId());
//                devopsTask.setCode(StringUtils.isBlank(t.getCode()) ? "D" + System.nanoTime() : t.getCode());
//                devopsTask.setFullId(t.getProductEpicId() + "/" + t.getProductStoryId() + "/" + t.getProductTaskId());
//                devopsTask.setIsLeaf("0");
//                devopsTask.setManager(t.getMoniterUser());
//                devopsTask.setManagerName(userKV.get(t.getMoniterUser()));
//                devopsTask.setVersion(1L);
//                devopsTask.setParentId(t.getProductStoryId());
//                devopsTask.setTaskGroupId(t.getProductTaskGroupId());
//                devopsTask.setPlanDetailId(t.getProductPlaneDetailId());
//                devopsTask.setPlanId(t.getProductPlaneId());
//                devopsTask.setProjectId(t.getSystemId());
//                devopsTask.setName(t.getTitle());
//                devopsTask.setSort(t.getSort());
//                devopsTask.setStatus(t.getStatus());
//                devopsTask.setRemark(StringUtils.isBlank(t.getRemark()) ? t.getTitle() : t.getRemark());
//                devopsTask.setPredictBeginTime(t.getPredictBeginTime());
//                devopsTask.setPredictEndTime(t.getPredictEndTime());
//                devopsTask.setPracticalBeginTime(t.getPracticalBeginTime());
//                devopsTask.setPracticalEndTime(t.getPracticalEndTime());
//                devopsTask.setHoursOfWork(t.getHoursOfWork());
//                devopsTask.setHoursOfWorkTruth(t.getHoursOfWorkTruth());
//                devopsTask.setHoursOfWorkUnit(t.getHoursOfWorkUnit());
////                            .num((long)e.getSort())
//                devopsTask.setLevel(t.getLevel());
//                devopsTask.setIsValid("Y");
//                devopsTask.setCreateTime(t.getCreateTime());
//                devopsTask.setCreateUser(t.getCreateUser());
//                devopsTask.setUpdateTime(t.getUpdateTime());
//                devopsTask.setUpdateUser(t.getUpdateUser());
//                devopsTask.setCreateUserName(userKV.get(t.getCreateUser()) == null ? "devops" : userKV.get(t.getCreateUser()));
//                devopsTask.setUpdateUserName(userKV.get(t.getUpdateUser()) == null ? "devops" : userKV.get(t.getUpdateUser()));
//                devopsTask.setLesseeId("devops");
//                devopsTasks.add(devopsTask);
//            });
//            devopsTaskService.saveTaskList(devopsTasks);
//            devopsTasks.clear();
//        }
//    }
//
//    @PostMapping("migrateProductBucket")
//    public void migrateProductBucket(String systemId) {
//        //查询所有的产品桶
//        HashMap<String, Object> paramMap = new HashMap<>();
//        paramMap.put("projectId", systemId);
//        String result = HttpUtil.post(URLConfig.CONSUMER_URL + "queryBucketByProjectId", paramMap);
//
//        //查询所有的产品计划
//        HashMap<String, Object> paramMap2 = new HashMap<>();
//        paramMap2.put("systemId", systemId);
//        String result2 = HttpUtil.post(URLConfig.CONSUMER_URL + "queryProductPlanBySystemId", paramMap2);
//        List<TProductPlane> plane = JSON.parseArray(result2, TProductPlane.class);
//        Map<Integer, String> planMap = plane.stream().collect(Collectors.toMap(TProductPlane::getProductPlaneYear, TProductPlane::getProductPlaneId));
//
//        List<TBucket> tBuckets = JSON.parseArray(result, TBucket.class);
//        System.out.println(tBuckets);
//        List<DevopsBucket> devopsBuckets = new ArrayList<>();
//        tBuckets.forEach(e -> {
//            DevopsBucket build = DevopsBucket.builder()
//                    //转为主计划 ID
//                    .bucketId(planMap.get(e.getCreateTime().getYear())).bucketName(e.getBucketName()).isValid("Y").lesseeId("devops").systemType(e.getSystemType()).createTime(e.getCreateTime()).createUser(e.getCreateUser()).createUserName(e.getCreateUserName()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).updateUserName(e.getUpdateUserName()).planId(planMap.get(e.getCreateTime().getYear())).build();
//            devopsBuckets.add(build);
//        });
//        System.out.println(plane);
//        System.out.println(devopsBuckets);
//
//        HashMap<String, Object> paramMap3 = new HashMap<>();
//        paramMap3.put("projectId", systemId);
//        String result3 = HttpUtil.post(URLConfig.CONSUMER_URL + "queryBucketFileByProjectId", paramMap3);
//        List<TBucketFile> tBucketFiles = JSON.parseArray(result3, TBucketFile.class);
//
//        List<DevopsBucketFile> devopsBucketFiles = new ArrayList<>();
//        tBucketFiles.forEach(e -> {
//            DevopsBucketFile build = DevopsBucketFile.builder().bucketFileId(e.getBucketFileId()).bucketFilePid(e.getBucketFilePid()).bucketFileCode(e.getBucketFileCode()).bucketFileName(e.getBucketFileName()).bucketFileRemark(e.getBucketFileRemark()).bucketFileType(e.getBucketFileType()).bucketFileUrl(e.getBucketFileUrl())
//                    //转为主计划 ID
//                    .bucketId(planMap.get(e.getCreateTime().getYear())).globalId(e.getSeq()).isValid("Y").lesseeId("devops").createTime(e.getCreateTime()).createUser(e.getCreateUser()).createUserName(e.getCreateUserName()).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).updateUserName(e.getUpdateUserName()).source("5").build();
//            devopsBucketFiles.add(build);
//        });
//        if (!devopsBuckets.isEmpty()) {
//            devopsBucketService.saveBatch(devopsBuckets);
//        }
//        if (!devopsBucketFiles.isEmpty()) {
//            devopsBucketFileService.saveBucketFile(devopsBucketFiles);
//        }
//
//    }
//
//
//    @PostMapping("migrateTask")
//    public void migrateTask() {
//        HashMap<String, Object> paramMap4 = new HashMap<>();
//        String plans = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllProjectPlan", paramMap4);
//        List<TPlane> planeList = JSON.parseArray(plans, TPlane.class);
//        System.out.println(planeList);
//
//        HashMap<String, Object> paramMap6 = new HashMap<>();
//        String users = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllUser", paramMap6);
//        List<VUserData> userDataList = JSON.parseArray(users, VUserData.class);
//        System.out.println(userDataList);
//        Map<String, List<VUserData>> userMap = userDataList.stream().collect(Collectors.groupingBy(VUserData::getAccountId));
//        Map<String, String> userKV = userDataList.stream().collect(Collectors.toMap(VUserData::getAccountId, VUserData::getName));
//        Map<String, String> userKV2 = userDataList.stream().collect(Collectors.toMap(VUserData::getAccountId, VUserData::getAccountName));
//
//
//        HashMap<String, Object> paramMap7 = new HashMap<>();
//        String tasks = HttpUtil.post(URLConfig.CONSUMER_URL + "queryAllTask", paramMap7);
//        List<TTask> taskList = JSON.parseArray(tasks, TTask.class);
////        System.out.println(taskList);
////        Map<String, List<TTask>> taskMap = taskList.stream().collect(Collectors.groupingBy(TTask::getSystemId));
//
//        List<DevopsTask> devopsTasks = new ArrayList<>();
//
////        for (TPlane tPlane : planeList) {
////            String systemId = tPlane.getSystemId();
////            List<TTask> tasks1 = taskMap.get(systemId);
//
//        taskList.forEach(t -> {
////            DevopsTask build = DevopsTask.builder().id(e.getTaskId()).code(StringUtils.isBlank(e.getCode()) ? "T" + System.nanoTime() : e.getCode()).fullId(e.getEpicId() + "/" + e.getStoryId() + "/" + e.getTaskId()).isLeaf("0").manager(e.getMoniterUser()).managerName(userKV.get(e.getMoniterUser())).parentId(e.getStoryId()).taskGroupId(e.getTaskGroupId()).planDetailId(e.getPlaneDetailId()).planId(e.getPlaneId()).projectId(e.getSystemId()).name(e.getTitle()).sort(e.getSort()).status(e.getStatus()).remark(StringUtils.isBlank(e.getRemark()) ? e.getTitle() : e.getRemark()).predictBeginTime(e.getPredictBeginTime()).predictEndTime(e.getPredictEndTime()).practicalBeginTime(e.getPracticalBeginTime()).practicalEndTime(e.getPracticalEndTime()).hoursOfWork(e.getHoursOfWork()).hoursOfWorkTruth(e.getHoursOfWorkTruth()).hoursOfWorkUnit(e.getHoursOfWorkUnit())
//////                            .num((long)e.getSort())
////                    .level(e.getLevel()).isValid("Y").createTime(e.getCreateTime()).createUser(e.getCreateUser()).createUserName(userKV.get(e.getCreateUser())).updateTime(e.getUpdateTime()).updateUser(e.getUpdateUser()).updateUserName(userKV.get(e.getUpdateUser())).lesseeId("devops").build();
////            devopsTasks.add(build);
//            DevopsTask devopsTask = new DevopsTask();
////                                DevopsTask taskBuild = DevopsTask.builder()
//            devopsTask.setId(t.getTaskId());
//            devopsTask.setCode(StringUtils.isBlank(t.getCode()) ? "D" + System.nanoTime() : t.getCode());
//            devopsTask.setFullId(t.getEpicId() + "/" + t.getStoryId() + "/" + t.getTaskId());
//            devopsTask.setIsLeaf("0");
//            devopsTask.setManager(t.getMoniterUser());
//            devopsTask.setManagerName(userKV.get(t.getMoniterUser()));
//            devopsTask.setVersion(1L);
//            devopsTask.setParentId(t.getStoryId());
//            devopsTask.setTaskGroupId(t.getTaskGroupId());
//            devopsTask.setPlanDetailId(t.getPlaneDetailId());
//            devopsTask.setPlanId(t.getPlaneId());
//            devopsTask.setProjectId(t.getSystemId());
//            devopsTask.setName(t.getTitle());
//            devopsTask.setSort(t.getSort());
//            devopsTask.setStatus(t.getStatus());
//            devopsTask.setRemark(StringUtils.isBlank(t.getRemark()) ? t.getTitle() : t.getRemark());
//            devopsTask.setPredictBeginTime(t.getPredictBeginTime());
//            devopsTask.setPredictEndTime(t.getPredictEndTime());
//            devopsTask.setPracticalBeginTime(t.getPracticalBeginTime());
//            devopsTask.setPracticalEndTime(t.getPracticalEndTime());
//            devopsTask.setHoursOfWork(t.getHoursOfWork());
//            devopsTask.setHoursOfWorkTruth(t.getHoursOfWorkTruth());
//            devopsTask.setHoursOfWorkUnit(t.getHoursOfWorkUnit());
////                            .num((long)e.getSort())
//            devopsTask.setLevel(t.getLevel());
//            devopsTask.setIsValid("Y");
//            devopsTask.setCreateTime(t.getCreateTime());
//            devopsTask.setCreateUser(t.getCreateUser());
//            devopsTask.setUpdateTime(t.getUpdateTime());
//            devopsTask.setUpdateUser(t.getUpdateUser());
//            devopsTask.setCreateUserName(userKV.get(t.getCreateUser()) == null ? "devops" : userKV.get(t.getCreateUser()));
//            devopsTask.setUpdateUserName(userKV.get(t.getUpdateUser()) == null ? "devops" : userKV.get(t.getUpdateUser()));
//            devopsTask.setLesseeId("devops");
//            devopsTasks.add(devopsTask);
//        });
//        devopsTaskService.saveTaskList(devopsTasks);
//    }

}

